<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="${pageContext.request.contextPath}/editor/jquery/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/editor/jquery/jquery.form.js"></script>
<title>Insert title here</title>
<script type="text/javascript">
$(function() { //ready事件的简写方式
	$("#userName").blur(function() {
		var pwReg = /^[A-Za-z0-9]+$/;
		var pReg = /^([h|H][o|O][n|N][g|G][b|B][e|E][i|I][x|X][i|I][n|N]).*$/;
		if(!pwReg.test($("#userName").val())){
			$("#sNa").attr("style","");
			$("#sNa").html("<font color='red'>用户名只能为数字和英文字母的任意组合！</font>");
		}else if(this.value.length<6 ) {
			$("#sNa").attr("style","");
			$("#sNa").html("<font color='red'>用户名不能少于6位！</font>");
		}else if(this.value.length>18){
			$("#sNa").attr("style","");
			$("#sNa").html("<font color='red'>用户名不能大于18位！</font>");
		}else{
			$.getJSON("${pageContext.request.contextPath}/user_isUnique.action",
					{"userName":$.trim(this.value), "_":new Date().getTime()}, 
			  function(jsonObject) {
				if (jsonObject.isUniqueSUCCESS) {
					$("#sNa").attr("style","");
					$("#sNa").html("<font color='red'>用户名称已经存在！</font>");
				}else {
					$("#sNa").attr("style","");
					$("#sNa").text("√");
				}
			 });
		
	   }
	});
	$("#pwd").blur(function() {
		var pwReg = /^[A-Za-z0-9]+$/;
		if(!pwReg.test($("#pwd").val())){
			$("#spw").attr("style","");
			$("#spw").html("<font color='red'>用户密码只能为数字和英文字母的任意组合！</font>");
		}else if(this.value.length<6){
			$("#spw").attr("style","");
			$("#spw").html("<font color='red'>用户密码不能少于6位！</font>");
		}else if(this.value.length>15){
			$("#spw").attr("style","");
			$("#spw").html("<font color='red'>用户密码不能大于15位！</font>");
		}else{
			$("#spw").attr("style","");
			$("#spw").text("√");
		}
		
	});
   $("#pwd1").blur(function() {
		pw1= $("#pwd").val();
		pw2= $("#pwd1").val();
		pw3= "";
		if(!pw2){
			$("#spw1").attr("style","");
			$("#spw1").html("<font color='red'>请输入密码！</font>");
	   }else if(pw1!=pw2){
			$("#spw1").attr("style","");
			$("#spw1").html("<font color='red'>两次输入密码不一致！</font>");
		}else{
			$("#spw1").attr("style","");
		    $("#spw1").text("√");	
       }
	});
 
     var options = {
    		  beforeSubmit:function(){
    			//设置所有的Ajax请求为同步
 				$.ajaxSetup({async:false});
    			//防止重复提交
 				$("#subm").attr("disabled", "disabled");
				$("#form1").css("cursor", "wait");
				//执行所有必输项的blur事件
				$(".required").blur();
				//循环SPAN
				var flag = true;
				$.each($(".requiredSpan"),function(){
					if(this.innerHTML != "√"){
						flag = false;
						return false;//退出循环
					}
				});
				if(!flag){
					$("#message").text("输入信息不合法，请检查");
					$("#subm").removeAttr("disabled");
					$("#form1").css("cursor", "auto");


				}
 				//重置为异步
 				$.ajaxSetup({async:true});
 				return flag;
    		 }, 
    		 success:function(jsonObject){
    			 if(jsonObject.saveShopNewSUCCESS){
    				 $("#subm").val("注册中...");
 					window.location.href='page_user_login.action';
			}else{
 					$("#message").text("注册失败...");
 				}
    			
              }
    };
    //和form标签绑定
	$("#form1").ajaxForm(options); 
});
</script>
</head>
<body>
<jsp:include page="top.jsp"></jsp:include>
      <center>
       用户注册:<br/>
   <form action="regist" method="post"  id="form1"  onsubmit="disable()">
   		用户名:<input type="text" name="u.userName" class="required" id="userName"/><span id="sNa"class="requiredSpan">6到18位字母和数字的任意组合</span><br/>
   		密码:<input type="password" name="u.password" class="required"id="pwd"/><br/><span id="spw"class="requiredSpan">6到15位字母和数字的任意组合</span><br/>
   		确认密码<input type="password"  onblur="d()"class="required"id="pwd1"/><label id="la1"></label><br/><span id="spw1"class="requiredSpan">两次必须一致</span><br/>
   		<p><span id="message" style="color: red;"></span></p>
   		<input type="submit" id="subm"name="Submit" value="注册"/>
   </form>
   </center>



</body>
</html>